// 加载背景图片 这个过程是异步的
const bg = new Image();
bg.src = 'img/background.png'

// 加载LOGO
const copyright = new Image();
copyright.src = 'img/shoot_copyright.png'

// 初始化四张飞机大战加载图
const loading_frame = new Image();
loading_frame.src = 'img/game_loading.png'
// const loading_frame = []
// loading_frame[0] = new Image();
// loading_frame[0].src = 'img/game_loading.png'
// loading_frame[1] = new Image();
// loading_frame[1].src = 'img/game_loading2.png'
// loading_frame[2] = new Image();
// loading_frame[2].src = 'img/game_loading3.png'
// loading_frame[3] = new Image();
// loading_frame[3].src = 'img/game_loading4.png'

// 初始化个人控制飞机的图片
const hero_frame = { live: [], death: [] };
hero_frame.live[0] = new Image();
hero_frame.live[0].src = 'img/me1.png'
hero_frame.live[1] = new Image();
hero_frame.live[1].src = 'img/me2.png'
hero_frame.death[0] = new Image();
hero_frame.death[0].src = 'img/me_destroy_1.png'
hero_frame.death[1] = new Image();
hero_frame.death[1].src = 'img/me_destroy_2.png'
hero_frame.death[2] = new Image();
hero_frame.death[2].src = 'img/me_destroy_3.png'
hero_frame.death[3] = new Image();
hero_frame.death[3].src = 'img/me_destroy_4.png'

// 初始化子弹图片
const b = new Image();
b.src = 'img/bullet1.png'

// 初始化敌机图片
const e1 = {
  live: [],
  death: []
}
e1.live[0] = new Image();
e1.live[0].src = 'img/enemy1.png'
e1.death[0] = new Image();
e1.death[0].src = 'img/enemy1_down1.png'
e1.death[1] = new Image();
e1.death[1].src = 'img/enemy1_down2.png'
e1.death[2] = new Image();
e1.death[2].src = 'img/enemy1_down3.png'
e1.death[3] = new Image();
e1.death[3].src = 'img/enemy1_down4.png'

const e2 = {
  live: [],
  death: []
}
e2.live[0] = new Image();
e2.live[0].src = 'img/enemy2.png'
e2.death[0] = new Image();
e2.death[0].src = 'img/enemy2_down1.png'
e2.death[1] = new Image();
e2.death[1].src = 'img/enemy2_down2.png'
e2.death[2] = new Image();
e2.death[2].src = 'img/enemy2_down3.png'
e2.death[3] = new Image();
e2.death[3].src = 'img/enemy2_down4.png'


const e3 = {
  live: [],
  death: []
}
e3.live[0] = new Image();
e3.live[0].src = 'img/enemy3_n1.png'
e3.live[1] = new Image();
e3.live[1].src = 'img/enemy3_n2.png'
e3.death[0] = new Image();
e3.death[0].src = 'img/enemy3_down1.png'
e3.death[1] = new Image();
e3.death[1].src = 'img/enemy3_down2.png'
e3.death[2] = new Image();
e3.death[2].src = 'img/enemy3_down3.png'
e3.death[3] = new Image();
e3.death[3].src = 'img/enemy3_down4.png'
e3.death[4] = new Image();
e3.death[4].src = 'img/enemy3_down5.png'
e3.death[5] = new Image();
e3.death[5].src = 'img/enemy3_down6.png'

// 初始化暂停图片
const pause = new Image();
pause.src = 'img/game_pause.png'

// 定义游戏状态
const START = 0;
const STARTING = 1;
const RUNNING = 2;
const PAUSE = 3;
const END = 4;

// canvas画布绘制 bg 对象的左上角坐标
// let x = 0;
// let y = 0;
// let x2 = 0;
// let y2 = -700;

// 天空类配置项
const SKY = {
  bg: bg,
  width: 480,
  height: 700,
  speed: 10
}

// 加载页面配置项
const LOADING = {
  frame: loading_frame,
  width: 480,
  height: 110,
  x: 0,
  y: 700 - 116,
  speed: 1000
}

// 个人控制战机配置项
const HERO = {
  frame: hero_frame,
  width: 102,
  height: 126,
  // x: 0,
  // y: 0,
  speed: 100
}

// 子弹配置项
const BULLET = {
  img: b,
  width: 5,
  height: 11
}

// 小飞机配置项
const E1 = {
  type: 1,
  width: 57,
  height: 51,
  life: 1,
  score: 1,
  frame: e1,
  minSpeed: 20,
  maxSpeed: 10
}
const E2 = {
  type: 2,
  width: 69,
  height: 99,
  life: 5,
  score: 5,
  frame: e2,
  minSpeed: 50,
  maxSpeed: 25
}
const E3 = {
  type: 3,
  width: 169,
  height: 258,
  life: 20,
  score: 20,
  frame: e3,
  minSpeed: 100,
  maxSpeed: 100
}